/*
 * Copyright (c) 2020 Nanjing Xiaoxiongpai Intelligent Technology Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <stdio.h>
#include <string.h>
#include <unistd.h>

#include "ohos_init.h"
#include "cmsis_os2.h"
#include "iot_errno.h"
#include "hi_gpio.h"
#include "hi_uart.h"
#include "cc2530.h"


char *data = "Hello, Harmony Os!\n";

void cc2530_uart_init(void)
{
    uint8_t uart_buff[UART_BUFF_SIZE] = {0};
    uint8_t *uart_buff_ptr = uart_buff;
    uint32_t ret;

    hi_uart_attribute attr = {0};
    attr.baud_rate = 9600;
    attr.data_bits = 8;
    attr.parity = 0;
    attr.stop_bits = 1;

    hi_uart_extra_attr extraAttr = {0};
    extraAttr.rx_block = HI_UART_BLOCK_STATE_NONE_BLOCK;
    extraAttr.tx_block = HI_UART_BLOCK_STATE_NONE_BLOCK;

    if(hi_uart_init(HI_UART_IDX_1, &attr, &extraAttr) != IOT_SUCCESS)
    {
        printf("Failed to init uart! Err code = %d\n", ret);
        return;
    }

    printf("UART Test Start\n");
   
}
/**
 * @brief 
 * 
 */
int cc2530_uart_read(uint8_t *uart_buff_ptr)
{
    // uint8_t uart_buff[UART_BUFF_SIZE] = {0};
    // uint8_t *uart_buff_ptr = uart_buff;
    //通过串口1接收数据
    return hi_uart_read(HI_UART_IDX_1, (hi_u8*)uart_buff_ptr, UART_BUFF_SIZE);
}

int cc2530_uart_write(char *data)
{
    hi_uart_write(HI_UART_IDX_1, (hi_u8*)data, strlen(data));
}
